def fruits_into_baskets(fruits):
  start = 0
  fruit_type = {}
  max_fruits_num = 0
  for end in range(len(fruits)):
    right_tree = fruits[end]
    if(right_tree not in fruit_type):
      fruit_type[right_tree] = 0
    fruit_type[right_tree] += 1

    while(len(fruit_type)>2):
      left_tree = fruits[start]
      start += 1
      fruit_type[left_tree] -= 1
      if(fruit_type[left_tree] == 0):
        del fruit_type[left_tree]
    
    max_fruits_num = max(max_fruits_num,end-start+1)

  return max_fruits_num


def main():
  print("Maximum number of fruits: " + str(fruits_into_baskets(['A', 'B', 'C', 'A', 'C'])))
  print("Maximum number of fruits: " + str(fruits_into_baskets(['A', 'B', 'C', 'B', 'B', 'C'])))


main()